﻿#ifndef WIDGET_H
#define WIDGET_H

#include <QMenu>
#include <QSystemTrayIcon>
#include <QTimer>
#include <QWidget>
#include <filelogger.h>
#include <progressdaemonthread.h>
#include <progressmonitorthread.h>
#include <progressscreenshotthread.h>

using namespace stefanfrings;

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
private:
    void installLogger();
    void uninstallLogger();

    void initTrayIconMenu();

    void initTrayIcon();
    void uninitTrayIcon();

    void initDataBase();

    void initWorkThread();
    void uninitWorkThread();

    void initParam();
public slots:
    void startMonitorThread();
    void stopMonitorThread();
    void startDaemonThread();
    void stopDaemonThread();
    void startScreenshotThread();
    void stopScreenshotThread();

    void restartProgram();//重启程序
public slots:
    void slot_daemonStatus(bool isRun);
    void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
private slots:
    void slot_showView();
    void slot_switchDaemon();
    void slot_exit();
    void on_progressMange_clicked();

    void on_switchDaemonBtn_clicked();

    void on_daemonLogBtn_clicked();

    void on_systemSetting_clicked();

private:
    Ui::Widget *ui;
    Logger *logger;//日志
    //托盘图标及菜单相关
    QSystemTrayIcon *trayIcon; //托盘图标
    QMenu *trayIconMenu; //托盘图标菜单
    QAction *showAction;
    QAction *switchAction;
    QAction *quitAction;
    //进程守护线程
    bool daemonStatus;

    bool autoStartDaemon;//自动启动守护
    bool openScreenshot;//进程截图
    //工作线程
    ProgressMonitorThread *progressMonitorThread;
    ProgressScreenshotThread *progressScreenshotThread;
    ProgressDaemonThread *progressDaemonThread;

protected:
    void closeEvent(QCloseEvent *event) override;

};
#endif // WIDGET_H
